function HandlePageWeeklyWage(gui, operator, now, options) {
  this._gui = gui;
  this._operator = operator;
  this._now = now;
  this._options = options;

  this._createElements();
};

HandlePageWeeklyWage.prototype._createElements = function() {
  var _self = this;
  this._popupBox = new PopupBox();
  this._popupBox2 = new PopupBox2();
  this._wage = WageDate.instance();
  
  tr = this._gui.mains.insertRow(-1);
  td = tr.insertCell(-1);
  td.style.backgroundColor = '#fff';
  td.colSpan = 2;
  td.appendChild(DOMUtils.getLoadingImage());
  
  this._loadData();
};

HandlePageWeeklyWage.prototype._loadData = function() {
  this._wageDates = null;
  this._parameters = null;
  this._retrieveWageDates();
};

HandlePageWeeklyWage.prototype._verifyData = function() {
  if (this._wageDates) {
    this._updateElements();
  }
};

HandlePageWeeklyWage.prototype._retrieveWageDates = function(page, condition, date, from, to, pos) {
  var _self = this;
  /*new RequestUtils()._read('wagedate', null, 'd.page=\'' + this._options.template + '\'', null, null, null, null, function(result, params) { _self._wageDates = result.data;
                                                                                                                                             _self._parameters = result;
                                                                                                                                             _self._verifyData.call(_self);
                                                                                                                                           }, null);
*/

  new RequestUtils()._mysql('wagedate', null, function(result, params) { _self._wageDates = result.data;
                                                                          _self._parameters = result;
                                                                          _self._verifyData.call(_self);
                                                                        }, {php:'customphp/mysqlread.php',pos: (pos) ? pos : null });     
};
//
//HandlePageWeeklyWage.prototype._retrieveWages = function() {
//  var _self = this;
//  var cond = '(e.status = 0 OR e.status = 1) AND (e.isWeeklyPay = 1) AND (e.particular LIKE \'%Wage%\')';
//  var args = '&c=' + cond;
//  new RequestUtils()._mysql('weeklywages', args, function(result, params) { _self._wages = result.data;
//                                                                            _self._verifyData.call(_self);
//                                                                          }, null);
//};

HandlePageWeeklyWage.prototype._updateElements = function() {
  var _self = this;
  DOMUtils.removeChildElements(this._gui.pagination);
  DOMUtils.removeTableRows(this._gui.mains, 1);
  DOMUtils.removeChildElements(this._gui.weeklywage);
  
  this._gui.date.value = (this._wage.date) ? SimpleDate.format(this._wage.date) : SimpleDate.format(this._now);
  this._gui.date.onclick = function() { var context = this;
                                        _self._changeDate.call(_self, this, _self._wage.date, function(sd) { _self._wage.date = sd; context.focus(); }, false);
                                        return false;
                                      };
  
  this._gui.pay.onclick = function() { var div = document.createElement('div');
                                       var pos = DOMUtils.findPos(this);
                                       var objects = [];
                                       var func1 = function() { if (objects.length != 0) {
                                                                  _self._popupBox2._close();
                                                                  var total = 0;
                                                                  _self._wage.page = _self._options.template;
                                                                  var total = 0;
                                                                  for (var j = 0, jl = objects.length; j < jl; j++) {
                                                                    var o = objects[j];
                                                                    total += parseFloat(o.amount, 10);
                                                                  }
                                                                  _self._wage.amount = total;
                                                                  new RequestUtils()._custom('weeklywage', '&date=' + JSON.stringify(_self._wage) + '&exp=' + JSON.stringify(objects), function(result, params) { _self._retrieveWageDates(); }, { pos: pos });
                                                                } else {
                                                                  window.alert('NO WEEKLY PAY');
                                                                }
                                                              };
                                       var func2 = function() { _self._popupBox2._close();
                                                              };
                                       MiscUtils.dialog(_self._popupBox2, pos, div, func1, func2, {t: 'Weekly Wage', width: 920, height: 100});
                                       new DialogWeeklyWage(div, objects, {user: _self._operator, now: _self._now, wage: _self._wage});
                                     };
  
  if (this._wageDates.length == 0) {
    tr = this._gui.mains.insertRow(-1);
    tr.className = 'roweven';
    td = tr.insertCell(-1);
    td.colSpan = 2;
    td.style.height = '24px';
    td.style.textAlign = 'center';
    td.style.borderRight = 'solid 1px #885b5d';
    td.appendChild(document.createTextNode('N/A'));
  }
  
  for (var i = 0, il = this._wageDates.length; i < il; i++) {
    var wage = this._wageDates[i];
    tr = this._gui.mains.insertRow(-1);
    tr.className = (tr.rowIndex % 2 == 0) ? 'roweven' : 'rowodd';
    
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #885b5d';
    td.style.height = '25px';
    td.style.textAlign = 'center';
    var a = document.createElement('a');
    a.href = '#';
    a._wage = wage;
    a.appendChild(document.createTextNode(SimpleDate.format(wage.date)));
    a.onclick = function() { var w = window.open('?p=pagemanager&t=pagetableweeklywage&m=' + JSON.stringify({a:1, b:5, c:2}) + '&opts=' + JSON.stringify({ wage: this._wage }), 'WeeklyWage', 'width=1024,height=768,scrollbars=1,location=0', true);
                             w.focus();
                           };
    td.appendChild(a);
    
    var span = document.createElement('span');
    span.style.margin = '0 0 0 5px';
    span.appendChild(document.createTextNode(DlmanageUtils.weekly(SimpleDate.toDate(wage.date).getDay())));
    td.appendChild(span);

    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #885b5d';
    td.style.textAlign = 'left';
    td.style.padding = '0 0 0 15px';
    td.appendChild(document.createTextNode('$' + parseFloat(wage.amount, 10).toFixed(2)));
  }
  Pagination.makePagedResults(this._gui.pagination, this._parameters.page, this._parameters.total, this._parameters.size, function(page, condition) { _self._retrieveWageDates.call(_self, page, _self._parameters.condition); }, this, document);
  
};


HandlePageWeeklyWage.prototype._changeDate = function(label, currentDate, onChangeFunc, showTime) {
  var _self = this;
  this._wContainer = document.createElement('div');
  this._wContainer.style.left = DOMUtils.findPos(label)[0] + 'px';
  this._wContainer.style.top = DOMUtils.findPos(label)[1] + 'px';
  this._popupBox._open(this._wContainer, { pos: DOMUtils.findPos(label) });
  
  var ds = new DateSelect(currentDate, null, { container: this._wContainer, showTime: showTime });
  ds._selectFunc = function(sd) { _self._selectDate.call(_self, sd, label, onChangeFunc, showTime); };
};

HandlePageWeeklyWage.prototype._selectDate = function(sd, label, onChangeFunc, showTime) {
  
  onChangeFunc(sd);
  this._showDate(sd, label, showTime);
  this._popupBox._close();
};

HandlePageWeeklyWage.prototype._showDate = function(sd, label, showTime) {
  if (sd) { 
    label.value = SimpleDate.format(sd, showTime);
  } else {
    label.value = '';
  }
};
